package com.woniuxy.carrental.service.impl;

import com.woniuxy.carrental.entity.Loss;
import com.woniuxy.carrental.entity.PageBean;
import com.woniuxy.carrental.entity.ResponseResult;
import com.woniuxy.carrental.mapper.LossMapper;
import com.woniuxy.carrental.service.LossService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-09-28 15:20
 */
@Service
public class LossServiceImpl implements LossService {


    @Resource
    LossMapper lossMapper;

    //新增定损
    @Override
    public void addLossService(Loss loss) {
        lossMapper.addLoss(loss);
    }

    //查询所有定损订单
    @Override
    public List<Loss> selectAllLossService() {
        List<Loss> losses = lossMapper.selectAllLoss();
        return losses;
    }

    //修改表中数据根据loss属性id
    @Override
    public void updataLossService(Loss loss) {
         lossMapper.updataLoss(loss);
    }

    //根据id删除表中指定列数据
    @Override
    public void deleteLossService(int id) {
    lossMapper.deleteLoss(id);
    }

    @Override
    public ResponseResult<PageBean<Loss>> selectLossByPageService(Loss loss,
        int pageIndex, int pageSize) {
        PageBean<Loss> pageBean = new PageBean<>();
        List<Loss> losses = lossMapper.selectLossByPage(loss, pageIndex, pageSize);
        //得到表中数据的总条数
        int i = lossMapper.selectCountLoss();
        pageBean.setBeanList(losses);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(i);
        return new ResponseResult<PageBean<Loss>>(pageBean,200,"nice");
    }

}
